package com.cctc.security.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.cctc.security.util.RequestUrl;

@Controller
@RequestMapping(RequestUrl.JSON)
public class JsonController 
{
    @ResponseBody
    @ResponseStatus(HttpStatus.OK)
    @RequestMapping(value = RequestUrl.INDEX, method = RequestMethod.GET, headers = "Accept=application/json",produces = { MediaType.APPLICATION_JSON_VALUE })
    public Object json(@RequestParam(value = "s") int size, HttpServletRequest request)
    {
//        String clientIp = request.getHeader("x-forwarded-for");
//        if ((clientIp == null) || (clientIp.length() == 0) || ("unknown".equalsIgnoreCase(clientIp)))
//        {
//            clientIp = request.getHeader("Proxy-Client-IP");
//        }
//        else if ((clientIp == null) || (clientIp.length() == 0) || ("unknown".equalsIgnoreCase(clientIp)))
//        {
//            clientIp = request.getHeader("WL-Proxy-Client-IP");
//        }
//        else if ((clientIp == null) || (clientIp.length() == 0) || ("unknown".equalsIgnoreCase(clientIp)))
//        {
//            clientIp = request.getRemoteAddr();
//        }
//        getLog().debug(clientIp);
        DemoJson ds = new DemoJson(size);
        return ds;
    }
    
    @ResponseBody
    @Secured("ROLE_ADMIN")
    @RequestMapping(value = "/2.html", headers = "Accept=application/json")
    public Object json1(HttpServletRequest request)
    {
        List<Integer> list = new ArrayList<Integer>();
        for (int i = 0; i < 10000; i++)
        {
            list.add(i);
        }
        return list;
    }
    
}
